let GameControl =require("GameControl");

let BangProp =require("BangProp");
cc.Class({
    extends: cc.Component,


    properties: {

        needDesCount:10,//
        squareScore:1,
        _rigid:{
            default:null,
            type:cc.RigidBody,
        },
        _box:{
            default:null,
            type:cc.PhysicsBoxCollider,
        },
        dropSpeed:100,

        effectLength:500,

        _startSize:0,//初始化的尺寸
        _maxSize:0,
    },


    start () {

        this._startSize =this.node.width;
        this._maxSize =this.needDesCount;

        this._rigid= this.addComponent(cc.RigidBody);
        this._rigid.enabledContactListener =true;
        this._rigid.type=cc.RigidBodyType.Static;

        this._box= this.addComponent(cc.PhysicsBoxCollider);
        this._box.size.width =this.node.width;
        this._box.size.height =this.node.height;
        this._box.apply();
    },

    // 每次处理完碰撞体接触逻辑时被调用
    onPostSolve: function (contact, selfCollider, otherCollider) {

        GameControl.instance.scoreCtl.AddScore(this.squareScore);

        this.needDesCount--;

        if(this.needDesCount===0){
            //生成星星

            let pos = this.node.parent.convertToWorldSpace(this.node.position);
            let pName="BossBall";
            cc.loader.loadRes("Prop",function (err, prefab) {

                for(let i=0;i<10;i++)
                {
                    let prop =cc.instantiate(prefab);
                    cc.director.getScene().addChild(prop);
                    let bp =prop.getComponent(BangProp);
                    bp.SendProp(pName);
                    prop.position=pos;

                }

            });


            this.Des();
        }
        let valueSize =(this.needDesCount/this._maxSize)*this._startSize;

        this.node.width =valueSize;
        this.node.height =valueSize;

        let boxCollder= this.node.getComponent(cc.PhysicsBoxCollider);
        boxCollder.size.width=valueSize;
        boxCollder.size.height =valueSize;
        boxCollder.apply();
    },

    Des(){
        this.node.destroy();
    },
    //(update(dt))
    UpdateFun(){

        this.node.y-=this.dropSpeed;
    },

    // update (dt) {},
});
